using UnityEngine;

public class XRandom
{
    public long cid { 
        get; private set; 
    }

    public int seed = 0;
    public int count = 0;

    public XRandom(long nId, int nSeed=0)
    {
        seed = nSeed;
        if (nSeed == 0)
        {
            seed = Random.Range(0, System.DateTime.Now.Millisecond);
        }

        cid = nId;
    }

    public int Update()
    {
        seed = (seed * 29 + 37) % 2147483647;
        return seed;
    }

    public int Range(int nMin, int nMax)
    {
        count++;
        return Rand(nMin, nMax);
    }

    public float Range(float fMin, float fMax)
    {
        return fMin + (fMax - fMin) * (Rand(0, 1000) * 0.001f);
    }

    public int Rand(int low, int up)
    {
        if (low == up || low > up)
        {
            return low;
        }

        return low + Update() % (up - low + 1);
    }
}
